********************************************
*** Note this file uses the predictions from the Graded response IRT model estimates
*** YOU NEED TO RUN TABLE 2 GRADED RESPONSE MODEL ESTIMATES FIRST to CREATE THIS - estimate_table2_figure3_siC.do
*** all the directory references may need to replace / with \ - sorry Windows users!!
**********************************

use "data/gsem_grm_prepost_1952.dta", replace

** limit to pres years for overtime distribution comparison estimate
gen sample = 1
replace sample = 0 if year==1954
replace sample = 0 if year==1958
replace sample = 0 if year==1962
replace sample = 0 if year==1966
replace sample = 0 if year==1970
replace sample = 0 if year==1974
replace sample = 0 if year==1978
replace sample = 0 if year==1982
replace sample = 0 if year==1986
replace sample = 0 if year==1990
replace sample = 0 if year==1994
replace sample = 0 if year==1998
replace sample = 0 if year==2002
tab year if sample==1

      
*** first estimate simple model to identify observed sample
gsem (partyid_base <- LPID@1, ologit) (partyaffect partyprespref partyvotehouse3 strongpartisan  <- LPID, ologit) [pw=VCF0009z], group(compareyears) intpoints(15)
replace sample = 0 if e(sample)==0

** can  now simply weight within year using ANES supplied weight
replace newweight = VCF0009z


**********************************************
*** THESE ESTIMATES BUILD UP TO SPEED UP/JUSTIFY THE FINAL ESTIMATES
*** THEY TAKE A LONG TIME - BUT ARE 
*********************************************

*** now estimate base model

gsem (partyid_base <- LPID@1, ologit) (partyaffect partyprespref partyvotehouse3 strongpartisan  <- LPID, ologit) (1964: attpartythermdiff <- LPID, ologit) (1968: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1972: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1976: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1980: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1984: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1988: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1992: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1996: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2000: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2004: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2008: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2012: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2016: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2020: attpartythermdiff attpresthermdiff <- LPID, ologit)  [pw=VCF0009z], group(compareyears) intpoints(15)  

est store base
estimates replay, coefleg

*** Now
** constraints defining symmetry

constraint 100 _b[/partyid_base:1952.compareyears#c.cut1]+_b[/partyid_base:1952.compareyears#c.cut2]=0
constraint 101 _b[/partyid_base:1956.compareyears#c.cut1]+_b[/partyid_base:1956.compareyears#c.cut2]=0
constraint 102 _b[/partyid_base:1960.compareyears#c.cut1]+_b[/partyid_base:1960.compareyears#c.cut2]=0
constraint 103 _b[/partyid_base:1964.compareyears#c.cut1]+_b[/partyid_base:1964.compareyears#c.cut2]=0
constraint 104 _b[/partyid_base:1968.compareyears#c.cut1]+_b[/partyid_base:1968.compareyears#c.cut2]=0
constraint 105 _b[/partyid_base:1972.compareyears#c.cut1]+_b[/partyid_base:1972.compareyears#c.cut2]=0
constraint 106 _b[/partyid_base:1976.compareyears#c.cut1]+_b[/partyid_base:1976.compareyears#c.cut2]=0
constraint 107 _b[/partyid_base:1980.compareyears#c.cut1]+_b[/partyid_base:1980.compareyears#c.cut2]=0
constraint 108 _b[/partyid_base:1984.compareyears#c.cut1]+_b[/partyid_base:1984.compareyears#c.cut2]=0
constraint 109 _b[/partyid_base:1988.compareyears#c.cut1]+_b[/partyid_base:1988.compareyears#c.cut2]=0
constraint 110 _b[/partyid_base:1992.compareyears#c.cut1]+_b[/partyid_base:1992.compareyears#c.cut2]=0
constraint 111 _b[/partyid_base:1996.compareyears#c.cut1]+_b[/partyid_base:1996.compareyears#c.cut2]=0
constraint 112 _b[/partyid_base:2000.compareyears#c.cut1]+_b[/partyid_base:2000.compareyears#c.cut2]=0
constraint 113 _b[/partyid_base:2004.compareyears#c.cut1]+_b[/partyid_base:2004.compareyears#c.cut2]=0
constraint 114 _b[/partyid_base:2008.compareyears#c.cut1]+_b[/partyid_base:2008.compareyears#c.cut2]=0
constraint 115 _b[/partyid_base:2012.compareyears#c.cut1]+_b[/partyid_base:2012.compareyears#c.cut2]=0
constraint 116 _b[/partyid_base:2016.compareyears#c.cut1]+_b[/partyid_base:2016.compareyears#c.cut2]=0
constraint 117 _b[/partyid_base:2020.compareyears#c.cut1]+_b[/partyid_base:2020.compareyears#c.cut2]=0


** constraints defining equality across years

constraint 118 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:2016.compareyears#c.cut1]=0
constraint 119 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:2012.compareyears#c.cut1]=0
constraint 120 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:2008.compareyears#c.cut1]=0
constraint 121 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:2004.compareyears#c.cut1]=0
constraint 122 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:2000.compareyears#c.cut1]=0
constraint 123 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:1996.compareyears#c.cut1]=0
constraint 124 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:1992.compareyears#c.cut1]=0
constraint 125 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:1988.compareyears#c.cut1]=0
constraint 126 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:1984.compareyears#c.cut1]=0
constraint 127 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:1980.compareyears#c.cut1]=0
constraint 128 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:1976.compareyears#c.cut1]=0
constraint 129 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:1972.compareyears#c.cut1]=0
constraint 130 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:1968.compareyears#c.cut1]=0
constraint 131 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:1964.compareyears#c.cut1]=0
constraint 132 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:1960.compareyears#c.cut1]=0
constraint 133 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:1956.compareyears#c.cut1]=0
constraint 134 _b[/partyid_base:2020.compareyears#c.cut1]=_b[/partyid_base:1952.compareyears#c.cut1]=0


gsem (partyid_base <- LPID@1, ologit) (partyaffect partyprespref partyvotehouse3 strongpartisan  <- LPID, ologit) (1964: attpartythermdiff <- LPID, ologit) (1968: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1972: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1976: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1980: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1984: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1988: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1992: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1996: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2000: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2004: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2008: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2012: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2016: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2020: attpartythermdiff attpresthermdiff <- LPID, ologit)  [pw=newweight], group(compareyears) intpoints(15) constraints(100/134)
estimates replay, byparm


*** Now redefine so that mean for 1952 is not fixed, log-likelihood improves (-285512.12 vs. -285527.16), still well behaved

gsem (partyid_base <- LPID@1, ologit) (partyaffect partyprespref partyvotehouse3 strongpartisan  <- LPID, ologit) (1964: attpartythermdiff <- LPID, ologit) (1968: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1972: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1976: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1980: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1984: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1988: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1992: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1996: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2000: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2004: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2008: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2012: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2016: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2020: attpartythermdiff attpresthermdiff <- LPID, ologit)  [pw=newweight], group(compareyears) intpoints(15) constraints(100/134) mean(1952: LPID@MU1) mean(1956: LPID@MU2)  mean(1960: LPID@MU3) mean(1964: LPID@MU4) mean(1968: LPID@MU5) mean(1972: LPID@MU6) mean(1976: LPID@MU7) mean(1980: LPID@MU8) mean(1984: LPID@MU9) mean(1988: LPID@MU10) mean(1992: LPID@MU11) mean(1996: LPID@MU12) mean(2000: LPID@MU13) mean(2004: LPID@MU14)  mean(2008: LPID@MU15)   mean(2012: LPID@MU16)  mean(2016: LPID@MU17)  mean(2020: LPID@MU18)
matrix beta = e(b)

## now balance party affect, party therm diff, and party strength too

constraint 203 _b[/attpartythermdiff:1964.compareyears#c.cut4]+_b[/attpartythermdiff:1964.compareyears#c.cut5]=0
constraint 204 _b[/attpartythermdiff:1968.compareyears#c.cut4]+_b[/attpartythermdiff:1968.compareyears#c.cut5]=0
constraint 205 _b[/attpartythermdiff:1972.compareyears#c.cut4]+_b[/attpartythermdiff:1972.compareyears#c.cut5]=0
constraint 206 _b[/attpartythermdiff:1976.compareyears#c.cut4]+_b[/attpartythermdiff:1976.compareyears#c.cut5]=0
constraint 207 _b[/attpartythermdiff:1980.compareyears#c.cut4]+_b[/attpartythermdiff:1980.compareyears#c.cut5]=0
constraint 208 _b[/attpartythermdiff:1984.compareyears#c.cut4]+_b[/attpartythermdiff:1984.compareyears#c.cut5]=0
constraint 209 _b[/attpartythermdiff:1988.compareyears#c.cut4]+_b[/attpartythermdiff:1988.compareyears#c.cut5]=0
constraint 210 _b[/attpartythermdiff:1992.compareyears#c.cut4]+_b[/attpartythermdiff:1992.compareyears#c.cut5]=0
constraint 211 _b[/attpartythermdiff:1996.compareyears#c.cut4]+_b[/attpartythermdiff:1996.compareyears#c.cut5]=0
constraint 212 _b[/attpartythermdiff:2000.compareyears#c.cut4]+_b[/attpartythermdiff:2000.compareyears#c.cut5]=0
constraint 213 _b[/attpartythermdiff:2004.compareyears#c.cut4]+_b[/attpartythermdiff:2004.compareyears#c.cut5]=0
constraint 214 _b[/attpartythermdiff:2008.compareyears#c.cut4]+_b[/attpartythermdiff:2008.compareyears#c.cut5]=0
constraint 215 _b[/attpartythermdiff:2012.compareyears#c.cut4]+_b[/attpartythermdiff:2012.compareyears#c.cut5]=0
constraint 216 _b[/attpartythermdiff:2016.compareyears#c.cut4]+_b[/attpartythermdiff:2016.compareyears#c.cut5]=0
constraint 217 _b[/attpartythermdiff:2020.compareyears#c.cut4]+_b[/attpartythermdiff:2020.compareyears#c.cut5]=0

constraint 300 _b[/partyaffect:1952.compareyears#c.cut2]+_b[/partyaffect:1952.compareyears#c.cut3]=0
constraint 301 _b[/partyaffect:1956.compareyears#c.cut2]+_b[/partyaffect:1956.compareyears#c.cut3]=0
constraint 302 _b[/partyaffect:1960.compareyears#c.cut2]+_b[/partyaffect:1960.compareyears#c.cut3]=0
constraint 303 _b[/partyaffect:1964.compareyears#c.cut2]+_b[/partyaffect:1964.compareyears#c.cut3]=0
constraint 304 _b[/partyaffect:1968.compareyears#c.cut2]+_b[/partyaffect:1968.compareyears#c.cut3]=0
constraint 305 _b[/partyaffect:1972.compareyears#c.cut2]+_b[/partyaffect:1972.compareyears#c.cut3]=0
constraint 306 _b[/partyaffect:1976.compareyears#c.cut2]+_b[/partyaffect:1976.compareyears#c.cut3]=0
constraint 307 _b[/partyaffect:1980.compareyears#c.cut2]+_b[/partyaffect:1980.compareyears#c.cut3]=0
constraint 308 _b[/partyaffect:1984.compareyears#c.cut2]+_b[/partyaffect:1984.compareyears#c.cut3]=0
constraint 309 _b[/partyaffect:1988.compareyears#c.cut2]+_b[/partyaffect:1988.compareyears#c.cut3]=0
constraint 310 _b[/partyaffect:1992.compareyears#c.cut2]+_b[/partyaffect:1992.compareyears#c.cut3]=0
constraint 311 _b[/partyaffect:1996.compareyears#c.cut2]+_b[/partyaffect:1996.compareyears#c.cut3]=0
constraint 312 _b[/partyaffect:2000.compareyears#c.cut2]+_b[/partyaffect:2000.compareyears#c.cut3]=0
constraint 313 _b[/partyaffect:2004.compareyears#c.cut2]+_b[/partyaffect:2004.compareyears#c.cut3]=0
constraint 314 _b[/partyaffect:2008.compareyears#c.cut2]+_b[/partyaffect:2008.compareyears#c.cut3]=0
constraint 315 _b[/partyaffect:2012.compareyears#c.cut2]+_b[/partyaffect:2012.compareyears#c.cut3]=0
constraint 316 _b[/partyaffect:2016.compareyears#c.cut2]+_b[/partyaffect:2016.compareyears#c.cut3]=0
constraint 317 _b[/partyaffect:2020.compareyears#c.cut2]+_b[/partyaffect:2020.compareyears#c.cut3]=0


constraint 400 _b[/strongpartisan:1952.compareyears#c.cut1]+_b[/strongpartisan:1952.compareyears#c.cut2]=0
constraint 401 _b[/strongpartisan:1956.compareyears#c.cut1]+_b[/strongpartisan:1956.compareyears#c.cut2]=0
constraint 402 _b[/strongpartisan:1960.compareyears#c.cut1]+_b[/strongpartisan:1960.compareyears#c.cut2]=0
constraint 403 _b[/strongpartisan:1964.compareyears#c.cut1]+_b[/strongpartisan:1964.compareyears#c.cut2]=0
constraint 404 _b[/strongpartisan:1968.compareyears#c.cut1]+_b[/strongpartisan:1968.compareyears#c.cut2]=0
constraint 405 _b[/strongpartisan:1972.compareyears#c.cut1]+_b[/strongpartisan:1972.compareyears#c.cut2]=0
constraint 406 _b[/strongpartisan:1976.compareyears#c.cut1]+_b[/strongpartisan:1976.compareyears#c.cut2]=0
constraint 407 _b[/strongpartisan:1980.compareyears#c.cut1]+_b[/strongpartisan:1980.compareyears#c.cut2]=0
constraint 408 _b[/strongpartisan:1984.compareyears#c.cut1]+_b[/strongpartisan:1984.compareyears#c.cut2]=0
constraint 409 _b[/strongpartisan:1988.compareyears#c.cut1]+_b[/strongpartisan:1988.compareyears#c.cut2]=0
constraint 410 _b[/strongpartisan:1992.compareyears#c.cut1]+_b[/strongpartisan:1992.compareyears#c.cut2]=0
constraint 411 _b[/strongpartisan:1996.compareyears#c.cut1]+_b[/strongpartisan:1996.compareyears#c.cut2]=0
constraint 412 _b[/strongpartisan:2000.compareyears#c.cut1]+_b[/strongpartisan:2000.compareyears#c.cut2]=0
constraint 413 _b[/strongpartisan:2004.compareyears#c.cut1]+_b[/strongpartisan:2004.compareyears#c.cut2]=0
constraint 414 _b[/strongpartisan:2008.compareyears#c.cut1]+_b[/strongpartisan:2008.compareyears#c.cut2]=0
constraint 415 _b[/strongpartisan:2012.compareyears#c.cut1]+_b[/strongpartisan:2012.compareyears#c.cut2]=0
constraint 416 _b[/strongpartisan:2016.compareyears#c.cut1]+_b[/strongpartisan:2016.compareyears#c.cut2]=0
constraint 417 _b[/strongpartisan:2020.compareyears#c.cut1]+_b[/strongpartisan:2020.compareyears#c.cut2]=0


** Stata fails to get feasible initial values when estimating all at once, build up on prev. estimates

matrix list beta
di beta[1,347]
di beta[1,348]
di (abs(beta[1,347])+abs(beta[1,348]))/2

matrix beta[1,347] = -1.4715334
matrix beta[1,348] = 1.4715334

matrix beta[1,355] = -1.4715334
matrix beta[1,356] = 1.4715334 

matrix beta[1,363] = -1.4715334
matrix beta[1,364] = 1.4715334 

matrix beta[1,371] = -1.4715334
matrix beta[1,372] = 1.4715334 

matrix beta[1,379] = -1.4715334
matrix beta[1,380] = 1.4715334 

matrix beta[1,387] = -1.4715334
matrix beta[1,388] = 1.4715334 

matrix beta[1,395] = -1.4715334
matrix beta[1,396] = 1.4715334 

matrix beta[1,403] = -1.4715334
matrix beta[1,404] = 1.4715334 

matrix beta[1,411] = -1.4715334
matrix beta[1,412] = 1.4715334 

matrix beta[1,419] = -1.4715334
matrix beta[1,420] = 1.4715334 

matrix beta[1,427] = -1.4715334
matrix beta[1,428] = 1.4715334 

matrix beta[1,435] = -1.4715334
matrix beta[1,436] = 1.4715334 

matrix beta[1,443] = -1.4715334
matrix beta[1,444] = 1.4715334 

matrix beta[1,451] = -1.4715334
matrix beta[1,452] = 1.4715334 

matrix beta[1,459] = -1.4715334
matrix beta[1,460] = 1.4715334 

matrix beta[1,601] = 11
matrix beta[1,602] = 11
matrix beta[1,603] = 11

gsem (partyid_base <- LPID@1, ologit) (partyaffect partyprespref partyvotehouse3 strongpartisan  <- LPID, ologit) (1964: attpartythermdiff <- LPID, ologit) (1968: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1972: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1976: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1980: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1984: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1988: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1992: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1996: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2000: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2004: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2008: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2012: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2016: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2020: attpartythermdiff attpresthermdiff <- LPID, ologit)  [pw=newweight], group(compareyears) intpoints(15) constraints(100/134 203/217) mean(1952: LPID@MU1) mean(1956: LPID@MU2)  mean(1960: LPID@MU3) mean(1964: LPID@MU4) mean(1968: LPID@MU5) mean(1972: LPID@MU6) mean(1976: LPID@MU7) mean(1980: LPID@MU8) mean(1984: LPID@MU9) mean(1988: LPID@MU10) mean(1992: LPID@MU11) mean(1996: LPID@MU12) mean(2000: LPID@MU13) mean(2004: LPID@MU14)  mean(2008: LPID@MU15)   mean(2012: LPID@MU16)  mean(2016: LPID@MU17)  mean(2020: LPID@MU18) from(beta)

matrix beta = e(b)
matrix list beta

di beta[1,173]
di beta[1,174]

di beta[1,191]
di beta[1,192]

di beta[1,209]
di beta[1,210]

di (abs(beta[1,191])+abs(beta[1,192]))/2
forval i = 174/191 { 
    matrix beta[1,`i'] = -1.6455163
}
forval i = 192/209 { 
    matrix beta[1,`i'] = 1.6455163
}

matrix beta[1,601] = 11
matrix beta[1,602] = 11
matrix beta[1,603] = 11


gsem (partyid_base <- LPID@1, ologit) (partyaffect partyprespref partyvotehouse3 strongpartisan  <- LPID, ologit) (1964: attpartythermdiff <- LPID, ologit) (1968: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1972: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1976: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1980: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1984: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1988: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1992: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1996: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2000: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2004: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2008: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2012: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2016: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2020: attpartythermdiff attpresthermdiff <- LPID, ologit)  [pw=newweight], group(compareyears) intpoints(15) constraints(100/134 203/217 300/317) mean(1952: LPID@MU1) mean(1956: LPID@MU2)  mean(1960: LPID@MU3) mean(1964: LPID@MU4) mean(1968: LPID@MU5) mean(1972: LPID@MU6) mean(1976: LPID@MU7) mean(1980: LPID@MU8) mean(1984: LPID@MU9) mean(1988: LPID@MU10) mean(1992: LPID@MU11) mean(1996: LPID@MU12) mean(2000: LPID@MU13) mean(2004: LPID@MU14)  mean(2008: LPID@MU15)   mean(2012: LPID@MU16)  mean(2016: LPID@MU17)  mean(2020: LPID@MU18) from(beta)


matrix beta = e(b)
matrix list beta


di beta[1,299]
di beta[1,300]

di beta[1,317]
di beta[1,318]

di beta[1,335]
di beta[1,336]

di (abs(beta[1,317])+abs(beta[1,318]))/2
forval i = 300/317 { 
    matrix beta[1,`i'] = -3.4017532
}
forval i = 318/335 { 
    matrix beta[1,`i'] = 3.4017532
}

matrix beta[1,601] = 11
matrix beta[1,602] = 11
matrix beta[1,603] = 11

*************************************
** ESTIMATE FIXED ESTIMATE 
** FIGURE/TABLE E.1 
************************************

gsem (partyid_base <- LPID@1, ologit) (partyaffect partyprespref partyvotehouse3 strongpartisan  <- LPID, ologit) (1964: attpartythermdiff <- LPID, ologit) (1968: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1972: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1976: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1980: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1984: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1988: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1992: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1996: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2000: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2004: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2008: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2012: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2016: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2020: attpartythermdiff attpresthermdiff <- LPID, ologit)  [pw=newweight], group(compareyears) intpoints(15) constraints(100/134 203/217 300/317 400/417) mean(1952: LPID@MU1) mean(1956: LPID@MU2)  mean(1960: LPID@MU3) mean(1964: LPID@MU4) mean(1968: LPID@MU5) mean(1972: LPID@MU6) mean(1976: LPID@MU7) mean(1980: LPID@MU8) mean(1984: LPID@MU9) mean(1988: LPID@MU10) mean(1992: LPID@MU11) mean(1996: LPID@MU12) mean(2000: LPID@MU13) mean(2004: LPID@MU14)  mean(2008: LPID@MU15)   mean(2012: LPID@MU16)  mean(2016: LPID@MU17)  mean(2020: LPID@MU18) from(beta)

estimates replay, byparm
predict theta_compareyears_grm_fixed if e(sample), latent intpoints(7)







******************************************************************
** NOW ESTIMATE VARYING RELEVANCE MODEL
** EMPIRICAL BAYES LATENT ESTIMATE USED TO GENERATE FIGURE 5/6
*****************************************************************

matrix beta = e(b)
matrix beta[1,601] = 12
matrix beta[1,602] = 12
matrix beta[1,603] = 12

gsem (partyid_base <- LPID@1, ologit) (partyaffect partyprespref partyvotehouse3 strongpartisan  <- LPID, ologit) (1964: attpartythermdiff <- LPID, ologit) (1968: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1972: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1976: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1980: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1984: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1988: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1992: attpartythermdiff attpresthermdiff <- LPID, ologit)  (1996: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2000: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2004: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2008: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2012: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2016: attpartythermdiff attpresthermdiff <- LPID, ologit)  (2020: attpartythermdiff attpresthermdiff <- LPID, ologit)  [pw=newweight], group(compareyears) intpoints(15) constraints(100/134 203/217 300/317 400/417) mean(1952: LPID@MU1) mean(1956: LPID@MU2)  mean(1960: LPID@MU3) mean(1964: LPID@MU4) mean(1968: LPID@MU5) mean(1972: LPID@MU6) mean(1976: LPID@MU7) mean(1980: LPID@MU8) mean(1984: LPID@MU9) mean(1988: LPID@MU10) mean(1992: LPID@MU11) mean(1996: LPID@MU12) mean(2000: LPID@MU13) mean(2004: LPID@MU14) mean(2008: LPID@MU15) mean(2012: LPID@MU16)  mean(2016: LPID@MU17)  mean(2020: LPID@MU18) from(beta) ginvariant(none)

estimates replay, byparm
predict theta_compareyears_grm_free if e(sample), latent intpoints(5)

saveold data/postcompareyear_gsem_grm_1952.dta, replace version(12)

